package edu.geo.geoutils;

import java.sql.Connection;
import java.sql.SQLException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;



public class TestUtilMap implements DBConnectionProvider {
	static Log log = LogFactory.getLog(TestUtilMap.class);
	static JDBCConnectionPool pool = null;
	private String dbparams = null ;
	private String password = null ;
	
	public TestUtilMap()
	{
		this.dbparams = "localhost:5432/geoinformatica";
		this.password ="musica'2"; 
	}
	
	
	public void setDbparams(String dbparams)
	{
	this.dbparams = dbparams;	
	}
	
	public void setPassword(String password)
	{
	this.password = password;	
	}
	
	public Connection getConnection() throws SQLException
	{
		Connection conn;
		if(pool == null)
		{
	        String dburl = System.getProperty( "dburl" );
	        if ( dburl == null )
	        {
	        	dburl = dbparams;
	        }
	    	log.info("Using host:"+dburl);        
	        String user = System.getProperty( "user" );
	        if ( user == null )
	        {
	        	user = "postgres";
	        }
	        String pwd = System.getProperty( "pwd" );
	        if ( pwd == null )
	        {
	        	pwd = this.password;
	        }

			pool = new JDBCConnectionPool("jdbc:postgresql://"+dburl, user, pwd);
		}
		conn = pool.getConnection();
        
		return conn;
	}
}
